package cn.xmkeshe.dao;

import cn.xmkeshe.model.Customer;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface ICustomerDao {

  @Delete("delete from customer where cuid = #{cuid}")
  public boolean delete(String cuid);


  @Select("select * from customer where cuid = #{cuid}")
  public Customer findById(String cuid);

  @Insert("insert into customer(cuid,title,password,phone,name,photo,credate) values (#{cuid},#{title},#{password},#{phone},#{name},#{photo},#{credate})")
  public boolean doCreate(Customer customer);

  @Select("SELECT * FROM customer LIMIT #{start},#{lineSize}")
  public List<Customer> findAllBySplit(Map<String,Object> params);

  @Select("select COUNT(cuid) from customer")
  public Integer getAllCount();

  @Update("UPDATE customer SET password=#{password} WHERE cuid=#{cuid}")
  public boolean doUpdateByPassword(@Param("cuid") String cuid,@Param("password") String password);

  @Select("SELECT * FROM customer where name like #{name} LIMIT #{currentPage},#{lineSize}")
  public List<Customer> findByName(@Param("currentPage") int currentPage, @Param("lineSize") int lineSize,@Param("name") String name);

//  邮箱注册
  @Insert("insert into customer (cuid,title,password,email,phone,name,photo,credate,confirm_code,is_valid,activation_time) values (#{cuid},#{title},#{password},#{email},#{phone},#{name},#{photo},#{credate},#{confirmCode},#{isValid},#{activationTime})")
  public int insertCustomer(Customer customer);

  @Select("select email,activation_time from customer where confirm_code = #{confirmCode}")
  public Customer selectByConfirmCode(String confirmCode);

  @Update("update customer set is_valid = 1 where confirm_code = #{confirmCode}")
  public int updateByConfirmCode(String confirmCode);

  @Select("select * from customer where email = #{email} and is_valid=1")
  public List<Customer> selectByEmail(String email);

  @Select("select * from customer where email = #{email}")
  public Customer selectOneByEmail(String email);
}
